import { createI18n } from "vue-i18n";
import { useConfigStore } from "@/store/modules/config";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import enCn from "element-plus/es/locale/lang/en";
import zh_cn from "./lang/zh-cn";
import en from "./lang/en";

const messages = {
  "zh-cn": {
    ...zhCn,
    ...zh_cn,
  },
  en: {
    ...enCn,
    ...en,
  },
};

const i18n = (pinia) => {
  const configStore = useConfigStore(pinia);
  return createI18n({
    legacy: false, // 解决报错的
    locale: configStore.globalI18n, // 默认语言
    fallbackLocale: "zh-cn",
    globalInjection: true,
    messages,
  });
};

export default i18n;
